#============================================
#知识点
#1.定义匿名函数lambda   lambda 参数:函数表达式
#2.主要用在临时使用一次的情况，一般与其他函数配合使用
#3.一些函数的使用map max sort sorted min filter 
#4.使用lambda 以max为例子  max(可迭代对象,key(可以不要) = 函数体 )
#5.运行方式就是先将可迭代对象转换为迭代器对象，如果没有key他就会依次取出迭代器参数比较大小,如果有key它就会
#依次取出迭代器参数传到key中的表达式或者函数(lambda表达式适用)返回出来的值，在进行比较
#============================================
# #可迭代对象在前，函数在后
# dic = {"小黑":10,"小红":20,"小绿":30,"小蓝":40}
# #max  min
# res = max(dic,key = lambda x:dic[x])
# print(res)
# res = min(dic,key = lambda x:dic[x])
# print(res)
# #sorted  返回一个列表
# res = sorted(dic,key = lambda x:dic[x],reverse = True) 
# print(res)
#============================================
# # 可迭代对象在后，函数在前
# ls = ["小黑qwq","小绿","小兰qwq","小红"]
# #map  映射可迭代对象  (函数,可迭代对象，初始值)
# res = map(lambda x:x+"123",ls)
# for i in res:
#     print(i)
# #filter  跳出需求对象  endswith("")以甚麽结尾   (判断函数true or flase,可迭代对象，初始值)
# res = filter(lambda x:x.endswith("qwq"),ls)
# for i in res: 
#     print(i)
# #reduce 累加  (函数,可迭代对象，初始值)
# from functools import reduce
# res = reduce(lambda x,y:x+y,[1,2,3,4,5],0)
# print(res)
# #注释以上都可以用生成式来写
#============================================
# s = ["1asdasd","2sfdgfdg","3sdfsdf","4asdas","5asdas","6asdsa"]
# for i in  s:
#     y = lambda i:" ".join(i)
#     print(y)
#============================================
# lis = [['qwq',1],['awa',9],['qop',3],['uiu',6]]
# lis.sort(key=lambda x:x[1])
# liss = sorted(lis,key=lambda x:x[1],reverse=True)
# print(liss)
# print(lis)

ls = ["小黑qwq","小绿","小兰qwq","小红"]

# res = map(lambda x:x[0:1],ls)
# for i in res:
#     print(i)

#
# res = filter(lambda x:x.endswith('qwq'),ls)
# for i in res:
#     print(i)

# from functools import reduce
#
# res = reduce(lambda x,y:x+y,[1,2,3,5],50)
# print(res)